using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.IO;

namespace EnsoNetServer
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            log4net.Config.XmlConfigurator.Configure();

            RemotingConfiguration.Configure("EnsoNetServer.exe.config", false);
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(CommandServer), "RPC2", WellKnownObjectMode.Singleton);

            try
            {
                IEnso enso = CommandServer.ConnectEnso();

                enso.DisplayMessage("<p>Launching .NET server...</p>");
            }
            catch (Exception e)
            {
                //TODO: Logging.
                MessageBox.Show("There was an error connecting to the Enso Launcher: " + e.Message, "Start-up Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Application.Exit();
            }

            CommandServer.LoadCommandlets();
            CommandServer.SetupFileSystemWatcher();
            
            Application.Run(new ConfigurationForm());
        }
    }
}